import {
  createRootRoute,
  Outlet,
  useNavigate,
  useLocation,
} from "@tanstack/react-router";
import { useEffect } from "react";

const RootLayout = () => {
  const navigate = useNavigate();
  const location = useLocation();

  // 当访问根路径时重定向到/movie/hot
  useEffect(() => {
    if (location.pathname === "/") {
      navigate({ to: "/movie/hot" });
    }
  }, [location.pathname, navigate]);

  return (
    <>
      <Outlet />
    </>
  );
};

export const Route = createRootRoute({ component: RootLayout });
